<?php
	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$telephone		= strip_tags($_POST['telephone']);
		$lat			= strip_tags($_POST['lat']);
		$lng			= strip_tags($_POST['lng']);
		$address			= $_POST['address'];
		$status			= $_POST['status']=='publish' ? '1': '0';
		$ip				= getUserIP();
		
		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/location/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_basename = basename($upload_fullpath);
		}

		$sql = "INSERT INTO `tbl_locations` (`location_id`, `title`, `telephone`, `address`, `lat`, `lng`, `thumb`, `date`, `status`) VALUES (NULL, '$title', '$telephone', '$address', '$lat', '$lng', '$upload_basename',  NOW(), '$status');";
		mysql_query($sql);
		redirect('../');
		exit;
	}
 
	include 'ckeditor/ckeditor.php';
	include 'ckeditor/ckfinder/ckfinder.php';
	
	$ckeditor = new CKEditor();
	$ckeditor->returnOutput			= true;
	$ckeditor->basePath				= '/backend/ckeditor/';
	$ckeditor->config['toolbar']	= 'Basic';
	$ckeditor->config['height']		= '100';
	$ckeditor->config['width']		= '500';

	CKFinder::SetupCKEditor($ckeditor, '/backend/ckeditor/ckfinder/');
	$addressHTML = $ckeditor->editor('address');
?>